package org.zoomdev.zoom.dao.driver;

import org.zoomdev.zoom.common.exceptions.ZoomException;
import org.zoomdev.zoom.dao.meta.TableKeyMeta;

import java.sql.Connection;

public abstract class SqlDriver {
    public static final String MYSQL = "MySQL";
    public static final String H2 = "H2";
    public static final String ORACLE = "Oracle";

    public static SqlDriver create(String productName) {
        if (MYSQL.equals(productName)) {
            return new MysqlDriver();
        }

        if (H2.equals(productName)) {
            return new H2Driver();
        }

//        if (Databases.ORACLE.equalsIgnoreCase(productName)) {
//            return new OracleDriver();
//        }
        throw new ZoomException(String.format("不支持的数据库产品:%s", productName));
    }

    /**
     * 保护字段，如mysql加上 `` oracle有可能需要加上""
     *
     * @param name
     * @return
     */
    public StringBuilder protectColumn(StringBuilder sb, String name) {
        return sb.append(name);
    }

    public StringBuilder protectTable(StringBuilder sb, String name) {
        return sb.append(name);
    }


    /**
     * 填充tableMeta的值
     *
     * @param tableMeta
     */
    public abstract void fill(Connection conn, TableKeyMeta tableMeta);
}
